//
//  MeAutCompleteViewController.m
//  DBAChain
//
//  Created by Mxionlly on 2018/9/10.
//  Copyright © 2018年 Evan. All rights reserved.
//

#import "MeAutCompleteViewController.h"
#import "MeAuthenticationTableViewCell.h"
#import "MeAutCompletesView.h"

@interface MeAutCompleteViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView    *tableView;
@property (nonatomic,strong)NSArray        *cellArray;
@property (nonatomic,strong)MeAutCompletesView *headView;
@property (nonatomic,strong)dataGeneralAuthInfo *authModel;
@end

@implementation MeAutCompleteViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"实名认证成功";
    self.cellArray = @[@"证件",@"银行卡号",@"支付宝账号"];
    [self.view addSubview:self.tableView];
    [self initUI];
}

- (id)initWithModel:(dataGeneralAuthInfo *)model {
    self = [super init];
    if (self) {
        self.authModel = [dataGeneralAuthInfo mj_objectWithKeyValues:model];
    }
    return self;
}

-(void)initUI{
    [self.headView.avatarImage sd_setImageWithURL:[NSURL URLWithString:[UserCenter shareCenter].user.imageUrl] placeholderImage:[UIImage imageNamed:@"icon_icon"]];
    self.headView.lbname.text = self.authModel.Name;
    self.headView.lbidCard.text = [UserCenter shareCenter].user.UserId;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setBlackStatus:YES];
}

#pragma mark - init
-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, distanceHeight, KScreenWidth, KScreenHeight-distanceHeight) style:UITableViewStyleGrouped];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor  = [UIColor clearColor];
        _tableView.scrollEnabled = YES;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
    }
    return _tableView;
}

-(MeAutCompletesView *)headView
{
    if (!_headView) {
        _headView = [[[NSBundle mainBundle] loadNibNamed:@"MeAutCompletesView" owner:nil options:nil] objectAtIndex:0];
        _headView.frame = CGRectMake(0, 0, KScreenWidth, 165);
    }
    return _headView;
}

#pragma mark - UITableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.cellArray count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.00001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 165;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return self.headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MeAuthenticationTableViewCell *cell = [MeAuthenticationTableViewCell cellWithTableView:tableView];
    cell.lbtitle.text =self.cellArray[indexPath.row];
    cell.textField.userInteractionEnabled = NO;
    [cell.textField setTextColor:UIColorFromRGB(0xA7A7A7)];
    if (indexPath.row == 0) {
        NSMutableString *idcard = self.authModel.IdentityCard.mutableCopy;
        [idcard replaceCharactersInRange:NSMakeRange(4, 8) withString:@"************"];
        cell.textField.text =idcard;
    }else if (indexPath.row == 1){
        NSMutableString *idcard = self.authModel.BankCard.mutableCopy;
        [idcard replaceCharactersInRange:NSMakeRange(4, 8) withString:@" **** **** **** "];
        cell.textField.text =idcard;
    }else{
        NSMutableString *idcard = self.authModel.Alipay.mutableCopy;
        [idcard replaceCharactersInRange:NSMakeRange(3, self.authModel.Alipay.length -3) withString:@"****"];
        cell.textField.text =idcard;
    }
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
